#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <map>

using namespace std;

int load_level_words (map <string, int> & words_level_map, string words_path, int words_level)
{
	ifstream obj_file (words_path.c_str());
	if (!obj_file)
	{
		cout << __LINE__ << " level 1 words file load fail!" << endl;
		//throw an exception
		return -1;	//使用异常的时候删除
	}
	string str, strs, stred, str_ing;
	while ( obj_file >> str )
	{
		//即使此单词在底一级出现过，只要在高一级再次出现，就赋予此单词高一级的难度值
		//因此此处不用判断以前此单词是否出现过
		words_level_map[str] = words_level;
	}
	obj_file.close();
	return 0;
}

int main (int argc, char* argv[])
{
	ifstream obj_file ("irregul_verb.new");
	string str1, str2, str3;
	map <string, int> level_words;
	char* file_name1 = "./irregular_verb1";
	char* file_name2 = "./irregular_verb2";
	char* file_name3 = "./irregular_verb3";
	char* file_name4 = "./irregular_verb4";
	char* file_name5 = "./irregular_verb5";
	char* file_name6 = "./irregular_verb6";
	char* file_name7 = "./irregular_verb7";
	load_level_words (level_words, "../words_levels/1.txt", 1);
	load_level_words (level_words, "../words_levels/2.txt", 2);
	load_level_words (level_words, "../words_levels/3.txt", 3);
	load_level_words (level_words, "../words_levels/4.txt", 4);
	load_level_words (level_words, "../words_levels/5.txt", 5);
	load_level_words (level_words, "../words_levels/6.txt", 6);
	
	ofstream irr_verb1 (file_name1);//, fstream::in | fstream::out);
	ofstream irr_verb2 (file_name2);//, fstream::in | fstream::out);
	ofstream irr_verb3 (file_name3);//, fstream::in | fstream::out);
	ofstream irr_verb4 (file_name4);//, fstream::in | fstream::out);
	ofstream irr_verb5 (file_name5);//, fstream::in | fstream::out);
	ofstream irr_verb6 (file_name6);//, fstream::in | fstream::out);
	ofstream irr_verb7 (file_name7);//, fstream::in | fstream::out);
	while (obj_file >> str1 >> str2 >> str3)
	{
		//cout << str1 << " " << str2 << " " << str3 << endl;
		//cout << level_words[str1] << endl;
		switch (level_words[str1])
		{
			case 1:
				{
					cout << level_words[str1] << str1 << " " << str2 << " " << str3 << endl;
					irr_verb1 << str2 << endl << str3 << endl;
					break;
				}
			case 2:
				{
					cout << level_words[str1] << str1 << " " << str2 << " " << str3 << endl;
					irr_verb2 << str2 << endl << str3 << endl;
					break;
				}
			case 3:
				{
					cout << level_words[str1] << str1 << " " << str2 << " " << str3 << endl;
					irr_verb3 << str2 << endl << str3 << endl;
					break;
				}
			case 4:
				{
					cout << level_words[str1] << str1 << " " << str2 << " " << str3 << endl;
					irr_verb4 << str2 << endl << str3 << endl;
					break;
				}
			case 5:
				{
					cout << level_words[str1] << str1 << " " << str2 << " " << str3 << endl;
					irr_verb5 << str2 << endl << str3 << endl;
					break;
				}
			case 6:
				{
					cout << level_words[str1] << str1 << " " << str2 << " " << str3 << endl;
					irr_verb6 << str2 << endl << str3 << endl;
					break;
				}
			default:
				{
					cout << level_words[str1] << str1 << " " << str2 << " " << str3 << endl;
					irr_verb7 << str2 << endl << str3 << endl;
				}
		}
	}
	irr_verb1.close();
	irr_verb2.close();
	irr_verb3.close();
	irr_verb4.close();
	irr_verb5.close();
	irr_verb6.close();
	irr_verb7.close();
	obj_file.close();
	return 0;
}

